import { isPicTitleDescStatusArr, isStringArray } from "@/types/editProps";
import type { IActions } from "@/types/store";

/**
 * * 设置文本状态
 * @param props 文本状态
 * @param status 文本状态值
 */
export const setTextStatus: IActions["setTextStatus"] = (props, status) => {
  props.status = status;
};

/**
 * * 添加选项状态
 * @param props 选项状态
 */
export const addOptionStatusItem: IActions["addOptionStatusItem"] = (props) => {
  if (isStringArray(props.status)) {
    props.status.push(`新增选项`);
  } else if (isPicTitleDescStatusArr(props.status)) {
    props.status.push({
      picTitle: "新增选项标题",
      picDesc: "新增选项描述",
      value: "",
    });
  }
};

/**
 * * 删除选项状态
 * @param props 选项状态
 * @param index 选项索引
 */
export const deleteOptionStatusItem: IActions["deleteOptionStatusItem"] = (props, index) => {
  if (props.status.length <= 2) {
    return false;
  }
  props.status.splice(index, 1);
  return true;
};

/**
 * * 设置当前状态索引
 * @param props 状态
 * @param index 状态索引
 */
export const setStatusIndex: IActions["setStatusIndex"] = (props, index) => {
  props.currentStatusIndex = index;
};

/**
 * * 设置单选图片选项的图片链接
 * @param props 选项状态
 * @param index 选项索引
 * @param link 图片链接
 */
export const setPicSelectOptionItem: IActions["setPicSelectOptionItem"] = (props, index, link) => {
  if (isPicTitleDescStatusArr(props.status)) {
    // console.log("设置图片链接", props.status[index], link, index);
    props.status[index].value = link;
    // console.log("设置图片链接", props.status[index]);
  }
};

/**
 * * 设置备注类型
 * @param props 选项状态
 * @param index 选项索引
 */
export const changeEditorVisible: IActions["changeEditorVisible"] = (status, type) => {
  if (type !== status.remarkType?.currentStatusIndex) {
    status.title.isShow = !status.title.isShow;
    status.desc.isShow = !status.desc.isShow;
    status.titleSize.isShow = !status.titleSize.isShow;
    status.descSize.isShow = !status.descSize.isShow;
    status.titleWeight.isShow = !status.titleWeight.isShow;
    status.descWeight.isShow = !status.descWeight.isShow;
    status.titleItatic.isShow = !status.titleItatic.isShow;
    status.descItatic.isShow = !status.descItatic.isShow;
    status.titleColor.isShow = !status.titleColor.isShow;
    status.descColor.isShow = !status.descColor.isShow;
    status.titleDevider!.isShow = !status.titleDevider?.isShow;
    status.descDevider!.isShow = !status.descDevider?.isShow;
  }
};

/**
 * * 设置是否使用评分辅助文本
 * @param status 状态
 * @param isUse 是否使用
 */
export const setRateIsUse: IActions["setRateIsUse"] = (status, isUse) => {
  status.rateSetting!.isUse = isUse;
};
